home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Storage / Bento / UpdatCtr.cpp < prev   
Encoding:
C/C++ Source or Header  |  1996-04-22  |  4.3 KB  |  174 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        UpdatCtr.cpp
  3.  
  4.     Contains:    Implementation of ODMemContainer class.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <6>     10/8/95    TJ        Fixes Recomended by Refball
  13.          <5>      8/3/95    RR        #1257260: Collapse B classes. Remove
  14.                                     somInit methods. Don't call IsInitialized
  15.                                     or SubclassResponsibility
  16.          <4>     7/21/95    VL        1270320: Create PlatformFile on stack.
  17.          <3>     5/26/95    VL        1251403: Multithreading naming support.
  18.          <2>      3/9/95    VL        1225504: Fixed Document ref-counting
  19.                                     problem.
  20.          <1>     2/10/95    VL        first checked in
  21. To Do:
  22. */
  23.  
  24. #define ODUpdateContainer_Class_Source
  25.  
  26. #define VARIABLE_MACROS
  27.  
  28. #include <UpdatCtr.xih>
  29.  
  30. #ifndef _PLFMDEF_
  31. #include "PlfmDef.h"
  32. #endif
  33.  
  34. #ifndef SOM_ODStorageSystem_xh
  35. #include <ODStor.xh>
  36. #endif
  37.  
  38. #ifndef SOM_CMDocument_xh
  39. #include <CMDoc.xh>
  40. #endif
  41.  
  42. #ifndef _MEMHDR_
  43. #include "MemHdr.h"
  44. #endif
  45.  
  46. #ifndef _TARGTHDR_
  47. #include "TargtHdr.h"
  48. #endif
  49.  
  50. #ifndef __CM_API__
  51. #include "CMAPI.h"
  52. #endif
  53.  
  54. #ifndef _EXCEPT_
  55. #include <Except.h>
  56. #endif
  57.  
  58. #ifndef _ODNEW_
  59. #include <ODNew.h>
  60. #endif
  61.  
  62. #ifndef _STORUTIL_
  63. #include <StorUtil.h>
  64. #endif
  65.  
  66. #ifndef _PLFMFILE_
  67. #include <PlfmFile.h>
  68. #endif
  69.  
  70. #ifndef _BARRAY_
  71. #include <BArray.h>
  72. #endif
  73.  
  74. #ifndef _ODMEMORY_
  75. #include <ODMemory.h>
  76. #endif
  77.  
  78. #pragma segment ODUpdateContainer
  79.  
  80. //==============================================================================
  81. // ODUpdateContainer
  82. //==============================================================================
  83.  
  84. //------------------------------------------------------------------------------
  85. // ODUpdateContainer: ~ODUpdateContainer
  86. //------------------------------------------------------------------------------
  87.  
  88. SOM_Scope void  SOMLINK ODUpdateContainersomUninit(ODUpdateContainer *somSelf)
  89. {
  90.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  91.     ODUpdateContainerMethodDebug("ODUpdateContainer","somUninit");
  92.     
  93.     ODSafeReleaseObject(_fTargetDocument);
  94.     ODSafeReleaseObject(_fTargetContainer);
  95.  
  96.     ODDisposeHandle(_fHandle);
  97. }
  98.  
  99. //------------------------------------------------------------------------------
  100. // ODUpdateContainer: InitContainer
  101. //------------------------------------------------------------------------------
  102.  
  103. SOM_Scope void  SOMLINK ODUpdateContainerInitContainer(ODUpdateContainer *somSelf, Environment *ev,
  104.         ODStorageSystem* storage, ODContainerID* id)
  105. {
  106.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  107.     ODUpdateContainerMethodDebug("ODUpdateContainer","InitContainer");
  108.     
  109.     SOM_CATCH return;
  110.  
  111.     /* Moved from somInit. SOM itself sets fields to zero
  112.         _fTargetContainer = kODNULL;
  113.         _fTargetDocument = kODNULL;
  114.         _fHandle = kODNULL;
  115.     */
  116.     
  117.     ODBoolean        fileLocked = kODTrue;
  118.     PlatformFile    file;
  119.     
  120.     ODVolatile(fileLocked);
  121.     TRY
  122.         file.Specify((FSSpec*) id->_buffer);
  123.         fileLocked = file.IsLocked();
  124.         if (fileLocked == kODFalse)
  125.             file.Lock();
  126.     
  127.         _fTargetContainer = (ODBentoContainer*) GetFileContainer(ev,
  128.                         storage->GetSession(ev),     
  129.                         (FSSpec*) id->_buffer);
  130.         _fTargetDocument = (CMDocument*) _fTargetContainer->AcquireDocument(ev, kODDefaultDocument);
  131.         
  132.         if (fileLocked == kODFalse)
  133.             file.Unlock();
  134.             
  135.     CATCH_ALL
  136.     
  137.         if (fileLocked == kODFalse)
  138.             file.Unlock();
  139.  
  140.         RERAISE;
  141.         
  142.     ENDTRY
  143.  
  144.     _fHandle = ODNewHandle(0);
  145.     
  146.     ODByteArray* ba = CreateByteArray(&_fHandle, sizeof(ODHandle));    
  147.     parent_InitContainer(somSelf, ev, storage, ba);
  148.     DisposeByteArray(ba);
  149. }
  150.  
  151. //------------------------------------------------------------------------------
  152. // ODUpdateContainer: GetTargetFileContainer
  153. //------------------------------------------------------------------------------
  154.  
  155. SOM_Scope ODBentoContainer*  SOMLINK ODUpdateContainerGetTargetContainer(ODUpdateContainer *somSelf, Environment *ev)
  156. {
  157.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  158.     ODUpdateContainerMethodDebug("ODUpdateContainer","GetTargetContainer");
  159.  
  160.     return _fTargetContainer;
  161. }
  162.  
  163. //------------------------------------------------------------------------------
  164. // ODUpdateContainer: GetTargetDocument
  165. //------------------------------------------------------------------------------
  166.  
  167. SOM_Scope CMDocument*  SOMLINK ODUpdateContainerGetTargetDocument(ODUpdateContainer *somSelf, Environment *ev)
  168. {
  169.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  170.     ODUpdateContainerMethodDebug("ODUpdateContainer","GetTargetDocument");
  171.  
  172.     return _fTargetDocument;
  173. }
  174.